# Copyright 2022 99Cloud, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# flake8: noqa
# fmt: off

"""Add Edge Multi Node

Revision ID: 2ba236337081
Revises: ff8920af4afa
Create Date: 2022-07-14 14:23:26.646807

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '2ba236337081'
down_revision = 'ff8920af4afa'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('edge_node',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('create_time', sa.DateTime(), nullable=False),
    sa.Column('update_time', sa.DateTime(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_edge_node_id'), 'edge_node', ['id'], unique=False)
    op.create_index(op.f('ix_edge_node_name'), 'edge_node', ['name'], unique=False)
    op.create_table('edge_node_rsu',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('create_time', sa.DateTime(), nullable=False),
    sa.Column('update_time', sa.DateTime(), nullable=False),
    sa.Column('edge_node_id', sa.Integer(), nullable=True),
    sa.Column('area_code', sa.String(length=64), nullable=True),
    sa.Column('name', sa.String(length=64), nullable=False),
    sa.Column('esn', sa.String(length=64), nullable=False),
    sa.Column('location', sa.JSON(), nullable=False),
    sa.ForeignKeyConstraint(['area_code'], ['area.code'], ),
    sa.ForeignKeyConstraint(['edge_node_id'], ['edge_node.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_edge_node_rsu_esn'), 'edge_node_rsu', ['esn'], unique=False)
    op.create_index(op.f('ix_edge_node_rsu_id'), 'edge_node_rsu', ['id'], unique=False)
    op.create_index(op.f('ix_edge_node_rsu_name'), 'edge_node_rsu', ['name'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_edge_node_rsu_name'), table_name='edge_node_rsu')
    op.drop_index(op.f('ix_edge_node_rsu_id'), table_name='edge_node_rsu')
    op.drop_index(op.f('ix_edge_node_rsu_esn'), table_name='edge_node_rsu')
    op.drop_table('edge_node_rsu')
    op.drop_index(op.f('ix_edge_node_name'), table_name='edge_node')
    op.drop_index(op.f('ix_edge_node_id'), table_name='edge_node')
    op.drop_table('edge_node')
    # ### end Alembic commands ###
